#include <iostream>

using namespace std;

struct TreeNode
{
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode(int x)
        :val(x)
        ,left(nullptr)
        ,right(nullptr)
    {}
    TreeNode(int x, TreeNode* _left, TreeNode* _right)
        :val(x)
        ,left(_left)
        ,right(_right)
    {}

};

class Solution 
{
public:
    TreeNode* Mirror(TreeNode* pRoot) 
    {
        if (!pRoot)
            return nullptr;

        TreeNode* left = Mirror(pRoot->left);
        TreeNode* right = Mirror(pRoot->right);

        pRoot->left = right;
        pRoot->right = left;

        return pRoot;
    }
};

void InOrder(TreeNode* root)
{
    if (!root)
    {
        return;
    }
    InOrder(root->left);
    cout << root->val << " ";
    InOrder(root->right);
}

int main()
{
    TreeNode* F = new TreeNode(11);
    TreeNode* E = new TreeNode(9);
    TreeNode* D = new TreeNode(7);
    TreeNode* C = new TreeNode(5);
    TreeNode* B = new TreeNode(10, E, F);
    TreeNode* A = new TreeNode(6, C, D);
    TreeNode* root = new TreeNode(8, A, B);
    
    Solution xz;
    TreeNode* phead = xz.Mirror(root);

    InOrder(phead);

	return 0;
}